package com.moon.game.manager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.moon.game.exception.GException;
import com.moon.game.resource.model.Fete;


/**
 * @description 祭祀管理
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-6 上午11:33:52
 */
public class FeteMG {
	private static final Logger log = Logger.getLogger(FeteMG.class);
	public static FeteMG instance = new FeteMG();
	private static Map<Integer, Fete> type2Fete = new HashMap<Integer, Fete>();
	private static Map<Integer, Fete> item2Fete = new HashMap<Integer, Fete>();
	private FeteMG() {}
	public void init() throws GException{
		if (instance == null) {
			instance = new FeteMG();
		}
		log.debug("load fetes end...");
		try {
			loadAllFeteConfig();
		} catch (Exception e) {
			throw new GException("load fetes err...");
		}
		log.debug("load fetes end...");
	}
	
	private void loadAllFeteConfig() {
		List<Fete> fetes = DBManager.queryFetes();
		if (fetes != null) {
			for (Fete fete : fetes) {
				if (fete.getSpecialId() != null && fete.getSpecialId() != 0) {
					item2Fete.put(fete.getSpecialId(), fete);
				}else {
					type2Fete.put(fete.getType(), fete);
				}
			}
		}
	}
	
	public final static Map<Integer, Fete> getType2Fete() {
		return type2Fete;
	}
	public final static Map<Integer, Fete> getItem2Fete() {
		return item2Fete;
	}
}
